package com.yvnze.ydyp.common.support;

import com.yvnze.ydyp.common.enums.ErrorCodeEnum;
import com.yvnze.ydyp.common.exception.SysException;
import org.springframework.validation.BindingResult;

/**
 * @author HaiPeng Wang
 * @date 2021/8/13 16:52
 * @Description:
 */
public class BaseController {
    protected void validateParams(BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            throw new SysException(
                    ErrorCodeEnum.PARAM_ERROR.getCode(),
                    ErrorCodeEnum.PARAM_ERROR.getMsg()+
                            bindingResult.getFieldError().getDefaultMessage()
            );
        }
    }

}
